<!doctype html>
<html lang="zh-CH">
<head>
	<meta charset="UTF-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	{{--<meta name="viewport" content="width=device-width, initial-scale=1">--}}
	<title>央票通</title>
	<link rel="stylesheet" href="./resource/css/index.css">
	<link rel="stylesheet" href="./resource/css/user_name.css">
</head>
<body>
<!-- 头部 -->
<?php
	$user_info = session_get(UserEnum::USER_INFO_SESSION_KEY);
?>
@include('common.index_head')
<!-- 个人中心 -->
<div class="cont-user">
	<div class="user-name">
		<div class="main">
			<div class="name-cont name-two">
				<div class="title">
					<span>支付密码</span>
				</div>
				<div class="form">
					<form action="/username_auth_thr" method="post" onsubmit="return check_all()">
						@if(!empty($real_name)&&!empty($id_card))
							<input type="hidden" name="real_name" value="{{$real_name}}">
							<input type="hidden" name="id_card" value="{{$id_card}}">
						@endif
						<div class="form-group">
							<label for=""><span>*</span>支付密码</label>
							<input type="password" class="form-control" id="pay_pwd" name="pay_pwd" onblur="check_pay()"><span id="t_pay" style='color:red'></span>
						</div>
						<div class="form-group form-code">
							<label for=""><span>*</span>短信验证码</label>
							{{--<input type="text" class="form-control" placeholder="请输入短信验证码" id="news_captcha" name="news_captcha"><span id="t_news"></span>--}}
							{{--<span class="code" id="f_captcha" >--}}
								{{--获取短信验证码--}}
							{{--</span>--}}
							<input type="text" class="left form-control" placeholder="请输入短信验证码" name="news_captcha" id='news_captcha' onblur="check_news()"><span id="t_news"></span>
							<span class="left code"  id="f_captcha" style="line-height: 40px;">获取短信验证码</span>
                            <input type="hidden" value="{{$user_info->mobile}}" id="mobile">
							<div class="code-hint" >验证码已发送到<span> {{substr_replace($user_info->mobile,'****',3,4)}}</span>，请注意查收</div>
						</div>
						<input type="submit" class="btn btn-register" value="确定">
					</form>
				</div>
			</div>
		</div>
	</div>
</div>
<!-- footer -->
@include('common.index_foot')
<script src="./resource/js/jquery-1.11.3.min.js"></script>
<script src="./resource/js/index.js"></script>
{{--<script src="./resource/js/user_code.js"></script>--}}
<script>
	function check_pay(){
		var pay_pwd = document.getElementById('pay_pwd').value;
		var reg=/^\d{6}$/
		if(reg.test(pay_pwd)){
			document.getElementById('t_pay').innerHTML = "";
			return true;
		}else{
			document.getElementById('t_pay').innerHTML = "支付密码为6位数字";
			return false;
		}
	}

	//获取短信验证码
	$('#f_captcha').bind('click',function foo() {
		var mobile = document.getElementById('mobile').value;
		if(check_pay()){
			var wait = 60;
			var int = function fetch_captcha() {
				if (wait == 0) {
					$("#f_captcha").bind("click", foo);
					$('#f_captcha').html('获取验证码');
					clearInterval(a)
					wait = 60;
				}
				else {
					$('#f_captcha').unbind("click", foo);
					$('#f_captcha').html("重新发送(" + wait + ")");
					wait--;
				}
			}
			var a = setInterval(int, 1000);
			$.ajax({
				url: "/verify_news",
				type: "POST",
				data: "mobile=" + mobile,
				success: function (msg) {
					if (msg == 10000) {
						$("#t_news").html("<span style='color:green'>验证码发送成功,10分钟内输入有效</span>");
						$('.code-hint').show();
					}else if(msg == 160040){
						$("#t_news").html("<span style='color:red'>您当天发送次数过多</span>");
						window.clearInterval(a);//停止计时器
						$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
						$(".form-code span.code").html("获取短信验证码");
						return false;
					}else{
						$("#t_news").html("<span style='color:red'>验证码发送错误</span>");
						window.clearInterval(a);//停止计时器
						$(".form-code span.code").removeAttr("disabled").css('cursor','pointer');//启用按钮
						$(".form-code span.code").html("获取短信验证码");
						return false;
					}
				}
			});
		}

	})

	function check_all(){
		var news_captcha = document.getElementById('news_captcha').value;
		var pay_pwd = document.getElementById('pay_pwd').value;
		var status = false;
		if(pay_pwd){
			if(news_captcha){
				var ajax = new XMLHttpRequest();
				ajax.onreadystatechange = function () {
					if (ajax.readyState == 4) {
						if (ajax.responseText == 1) {
							status = true
						}else if(ajax.responseText == 2){
							document.getElementById("t_news").innerHTML = "<span style='color:red'>验证码已过期</span>";
						}else{
							document.getElementById("t_news").innerHTML = "<span style='color:red'>验证码错误</span>";
						}
					}
				}
				//与服务器建立连接
				ajax.open('post', '/js_verify_user_news', false);
				ajax.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
				ajax.send('news_captcha='+news_captcha);
				return status;
			}else{
				return false;
			}

		}

		return check_pay();
	}
</script>
</body>
</html>